package com.njlime.sys.repository;

import com.njlime.core.base.repository.impl.BaseDaoImpl;
import com.njlime.core.utils.StringUtil;
import com.njlime.sys.entities.UnitWxConfig;
import com.njlime.sys.entities.UserConfig;
import org.springframework.stereotype.Repository;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

/**
 * Created by Dean on 2017-7-27.
 */
@Repository
public class UserConfigDaoImpl extends BaseDaoImpl<UserConfig> {

    /**
     * 根据单位获取微信设置
     * @param unitId
     * @return
     */
    public List<Map<String,Object>> list(int unitId){
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select t.*,d.name,d.remark from t_user_config t ");
        sb.append("join t_user_config_define d on d.id = t.define_id ");
        sb.append("where unit_id = ? and del = 0 ");
        arrList.add(unitId);
        return getListJdbc(sb.toString(),arrList);
    }


    public int updateStatus(int id){
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("update t_user_config set status = 2 ");

        sb.append(" where id = ?");
        arrList.add(id);
        return updateJdbc(sb.toString(),arrList);
    }

    /**
     * 定义列表
     * @return
     */
    public List<Map<String,Object>> defineList(){
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("select * from t_user_config_define");
        return getListJdbc(sb.toString(),arrList);
    }

    /**
     * 删除
     * @param id
     * @return
     */
    public int del(int id){
        StringBuilder sb = new StringBuilder();
        List<Object> arrList = new ArrayList<Object>();
        sb.append("update t_user_config set del = 1 where id = ?");
        arrList.add(id);
        return updateJdbc(sb.toString(),arrList);
    }
}
